#!/bin/bash

# Note: This file is not part of the metis package.  It is provided by
# the authors of WARP3D to aid users in compiling the metis library
# on their system.

# Compile and install metis within warp

# Check to make sure WARP3D_HOME is set
[ -z "$WARP3D_HOME" ] && echo "Need to set WARP3D_HOME before proceeding." && exit 1

# Move directories for you
cd $WARP3D_HOME/linux_packages/source/metis-4.0

# Default compiler
CC=gcc

# Other defaults (don't let user change)
OPTFLAG=-O2
AR="ar rv"
RANLIB=ranlib

# Ask if you'd like to overwrite the default compiler
echo 'Input C compiler (CC)'
echo 'Default: '$CC
read -p ": " OPT
[ -n "$OPT" ] && CC=$OPT
echo ""

# Clean up first I suppose
./clean_metis

# Write out Makefile.in
echo -e "CC = $CC \nOPTFLAGS = $OPTFLAG \nAR = $AR \nRANLIB = $RANLIB" > Makefile.in

# Make
make

# We only need the one library
echo "Installing metis..."
cp libmetis.a $WARP3D_HOME/linux_packages/lib

./clean_metis
